﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Vega.USiteBuilder;
using SPCFMedicineInformer.DocumentTypes.Base;
using SPCFMedicineInformer.DocumentTypes;
using umbraco.NodeFactory;
using Fonqi.Umbraco;

namespace SPCFMedicineInformer.UserControls
{
    public partial class PageHeaderControl : WebUserControlBase<PageBase>
    {
        public bool IsAuthenticated { get; set; }
        public FrontPage FrontPageDoc
        {
            get { return NodeLocator.GetNodeOfExactType<FrontPage>(); }
        }
        public ContactUsPage ContactUsPageDoc
        {
            get { return NodeLocator.GetNodeOfExactType<ContactUsPage>(); }
        }
        public RegistrationPage RegistrationPageDoc
        {
            get { return NodeLocator.GetNodeOfExactType<RegistrationPage>(); }
        }
        public ContentPage AboutUsDoc
        {
            get { return NodeLocator.GetNodeOfExactType<ContentPage>(); }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            IsAuthenticated = HttpContext.Current.User.Identity.IsAuthenticated;
            var CategoryList = NodeLocator.GetNodesOfExactType<MedicineCategory>();
            rptMedCategory.DataSource = CategoryList;
            rptMedCategory.DataBind();
        }

        public string IsCurrentNode(int? menuId, bool withClassElement, bool checkChildren)
        {
            if (!menuId.HasValue) return string.Empty;
            var currentId = Node.getCurrentNodeId();
            if (checkChildren)
            {
                if (menuId.Value == currentId || NodeController.IsNodeDescendantOfNode(currentId, menuId.Value))
                    return withClassElement ? "class=\"selected\"" : "selected";
            }
            else
            {
                if (menuId.Value == currentId)
                    return withClassElement ? "class=\"selected\"" : "selected";
            }

            return string.Empty;
        }
    }
}